package keyfun.utils 
{
	/**
	 * ...
	 * @author Key Hui
	 */
	public class ResizeUtil
	{
		// resize to max if exceed
		public static function resizeObject(obj:Object, maxW:Number, maxH:Number):void 
		{
			//trace("resize max");
			// calculation ratio to which resize takes 
			var r:Number = obj.height / obj.width;
			
			if (r <= 1)
			{
				if (obj.width > maxW)
				{
					obj.width = maxW;
					obj.height = Math.round(obj.width * r);
				}
				
				if (obj.height > maxH)
				{
					obj.height = maxH;
					obj.width = Math.round(obj.height / r);
				}
			}
			else
			{
				if (obj.height > maxH)
				{
					obj.height = maxH;
					obj.width = Math.round(obj.height / r);
				}
				
				if (obj.width > maxW)
				{
					obj.width = maxW;
					obj.height = Math.round(obj.width * r);
				}
			}
		}
		
	}

}